<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import { lastThreeMonthData } from "@/api/system/info";
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
     bactNo:{
    	type:String,
    }
  },
  data() {
    return {
      chart: null,
      expireOneMonth:'',
      expireTwoMonth:'',
      expireTirMonth:'',
      expireCount1:'',
      expireCount2:'',
      expireCount3:'',
    }
  },
	created(){
	lastThreeMonthData(this.bactNo).then((res)=>{    
		console.log(res);
		if(res.code==200){
			this.expireOneMonth = this.fomateData(res.data[0].datetime);
			this.expireTwoMonth = this.fomateData(res.data[1].datetime);
			this.expireTirMonth = this.fomateData(res.data[2].datetime);
			this.expireCount1 = res.data[0].invalidCount;
			this.expireCount2 = res.data[1].invalidCount;
			this.expireCount3 = res.data[2].invalidCount;
				this.initChart()
	}
  })
	},
  mounted() {
    this.$nextTick(() => {
     
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    
    this.chart.dispose()
    this.chart = null
  },
  methods: {
  	fomateData(time){
  	//	return time.substring(0,4)+'年'+time.substring(4,6)+'月'
  		return time.substring(4,6)+'月'
  	},
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: [this.expireOneMonth+': '+this.expireCount1+'张', this.expireTwoMonth+': '+this.expireCount2+'张', this.expireTirMonth+': '+this.expireCount3+'张']
        },
        series: [
          {
            name: '即将到期卡',
            type: 'pie',
//          roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '42%'],
            data: [
              { value: this.expireCount1, name: this.expireOneMonth+': '+this.expireCount1+'张'},
              { value: this.expireCount2, name: this.expireTwoMonth+': '+this.expireCount2+'张'},
              { value: this.expireCount3, name: this.expireTirMonth+': '+this.expireCount3+'张'},
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
    
  }
}
</script>
